<template>
  <el-select v-model="selectedUser">
    <el-option v-for="(item, index) in userList" :key="index" :label="item.nickName"
      :value="{ value: item.userId, label: item.nickName }" />
  </el-select>
</template>

<script setup lang="ts">
import { listUser } from '@/api/system';
import { type UserVO } from '@/api/system/types';
import { computed, ref, onMounted } from 'vue';
const props = withDefaults(defineProps<{ modelValue: string }>(), {
  modelValue: ''
});
const userList = ref<UserVO[]>([]);
const selectedUser = computed({
  get() {
    return props.modelValue || '';
  },
  set(value) {
    emit('update:modelValue', value);
  }
});
const emit = defineEmits(['update:modelValue']);
onMounted(async () => {
  const res: any = await listUser({ pageNum: 1, pageSize: 500 });
  if (res.code === 200) {
    userList.value = res.rows ? [...res.rows] : [];
  }
});
</script>
<style scoped></style>
